package com.gk.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.pojo.TbMemberLevel;
import com.eight.vo.ComResult;
import com.eight.vo.TbMemberLevelVo;
import com.gk.fein.UserEnableCouponFein;
import com.gk.service.TbMemberLevelService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会员等级控制层
 * @author: GK
 * @date: 2023/2/28 10:41
 * @version:No1.0
 */
@RestController
@RequestMapping("/customer/api/tbMemberLevel/")
public class TbMemberLevelApi {
    @Resource
    private TbMemberLevelService tbMemberLevelService;

    /**
     * 分页条件查询
     * @param tbMemberLevelVo 查询条件
     * @param pageIndex 当前页
     * @param pageSize 页中数据数量
     * @return  响应前端
     */
    @PostMapping("selectAll/{pageIndex}/{pageSize}")
    public ComResult selectAll(@RequestBody TbMemberLevelVo tbMemberLevelVo, @PathVariable Integer pageIndex, @PathVariable Integer pageSize){
        Page<TbMemberLevel> tbMemberLevelPage = tbMemberLevelService.selectAll(tbMemberLevelVo, pageIndex, pageSize);
        if(tbMemberLevelPage!=null){
            return new ComResult(2000,"查询成功",tbMemberLevelPage);
        }else{
            return new ComResult(5000,"查询失败");
        }
    }

    /**
     * 查询所有会员等级
     * @return 响应前端
     */
    @PostMapping("selectName")
    public ComResult selectName(){
        return tbMemberLevelService.selectName();
    }

    /**
     * 根据ID删除会员等级
     * @param id 条件
     * @return 响应前端
     */
    @PostMapping("deleteFindId/{id}")
    public ComResult deleteFindId(@PathVariable Integer id){
        System.out.println(id);
      return   tbMemberLevelService.deleteFindId(id);
    }

    /**
     * 添加会员等级
     * @param tbMemberLevel 添加的会员等级
     * @return 响应前端
     */
    @PostMapping("insertMemberLevel")
    public ComResult insertMemberLevel(@RequestBody TbMemberLevel tbMemberLevel){
        return tbMemberLevelService.insertMemberLevel(tbMemberLevel);
    }

    /**
     * 修改会员等级信息
     * @param tbMemberLevel 修改的信息
     * @return 响应前端
     */
    @PostMapping("updateMemberLevel")
    public ComResult updateMemberLevel(@RequestBody TbMemberLevel tbMemberLevel){
        return tbMemberLevelService.updateMemberLevel(tbMemberLevel);
    }

}
